package calculator;

import java.lang.reflect.InvocationTargetException;

public class CalculatorProxy {

	private Calculator calculator;
	private Validator validator;

	public CalculatorProxy(Calculator calculator2, Validator validator) {
		this.calculator = calculator2;
		this.validator = validator;
	}

	public Integer binaryOperation(String method, Integer left, Integer right)
			throws NoSuchMethodException, IllegalAccessException,
			InvocationTargetException, OverflowException {
		Long result = (Long) calculator.getClass()
				.getMethod(method, Integer.class, Integer.class)
				.invoke(calculator, left, right);
		validator.validate(result);
		return result.intValue();
	}

}
